home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)reve_proc.c 1.9 91/11/07
- *
- * Main routine for the separate play_reve program.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
-
- struct reve_in in ; /* Input supplied on standard input. */
- struct reve_out out ; /* Results written to standard output. */
-
- int sin ; /* Size of the input buffer. */
-
- int debug = FALSE ; /* If set, prints out various debug messages. */
- int saveres = FALSE ; /* If set, save computer results to log file. */
-
- char edgefile[MAXLINE] ; /* Location of the reve edge table file. */
- char progname[MAXLINE] ; /* The name of this program. */
-
- /* REVE global variables */
-
- int damier[NIVEAUMAX][64] ; /* Boards at different depth level */
- int tacouleur, macouleur ; /* Your and my colors during evaluation */
- int mnb, profmax ; /* Number of moves played, current max. depth */
- int max_depth = 2 ; /* Computer strategy - maximum depth. */
- int vp0, vo0 ; /* Current mobility components */
- long c1, c2, c3 ; /* Constants used in evaluation function */
- long edges[6561] ; /* Edges Stability Table */
- long note ; /* Note value for current computer move. */
- time_t savetime ; /* Restore correct time after a suggestion. */
- time_t timeleft ; /* Amount of time left for computer moves. */
-
- FILE *find_file P((char *)) ;
-
- int main P((int, char **)) ;
-
- void get_options P((int, char **)) ;
- void getparam P((char *, char **, char *)) ;
- void init_edge_table P((char *)) ;
- void show_best P((int, long)) ;
-
-
- /*ARGSUSED*/
- int
- main(argc, argv)
- int argc ;
- char *argv[] ;
- {
- int reply ;
-
- STRCPY(progname, argv[0]) ; /* Save program name for later use. */
- get_options(argc, argv) ; /* Extract command line options. */
- for (;;)
- {
- sin = sizeof(struct reve_in) ;
- if ((reply = read(0, (char *) &in, sin)) > 0)
- {
- if (in.type == M_TIME) timeleft = in.timeleft ;
- else if (in.type == M_PROFMAX) max_depth = in.level ;
- else
- {
- if (in.type == M_SUGGESTION) savetime = timeleft ;
- play_reve(in.board, in.player, in.level,
- &out.move, (long *) &out.note) ;
- out.type = in.type ;
- WRITE(1, (char *) &out, sizeof(struct reve_out)) ;
- if (in.type == M_SUGGESTION) timeleft = savetime ;
- }
- }
- else if (reply == 0) exit(1) ;
- }
- }
-
-
- FILE *
- find_file(filename)
- char *filename ;
- {
- char name[MAXLINE], *paths, *ptr ;
- int i = 0 ;
- FILE *fp = NULL ;
-
- if ((fp = fopen(filename, "r")) == NULL)
- {
- paths = getenv("PATH") ;
- if ((ptr = paths) && filename[0] != '/')
- for (;;)
- if (*ptr == ':' || *ptr == 0)
- {
- if (*ptr == 0) break ;
- name[i++] = '/' ;
- name[i] = 0 ;
- STRCAT(name, edgefile) ;
- if ((fp = fopen(name, "r")) != NULL) break ;
- if (*ptr == '\0') break ;
- ptr++ ;
- i = 0 ;
- }
- else name[i++] = *ptr++ ;
- }
- return(fp) ;
- }
-
-
- void
- get_options(argc, argv)
- int argc ;
- char *argv[] ;
- {
- INC ;
- while (argc > 0)
- {
- if (argv[0][0] == '-')
- switch (argv[0][1])
- {
- case 'd' : if (EQUAL(argv[0], "-debug")) debug = TRUE ;
- break ;
- case 'e' : INC ;
- getparam(edgefile, argv, "-e needs an edgetable file") ;
- init_edge_table(edgefile) ;
- break ;
- case 'l' : if (EQUAL(argv[0], "-log")) saveres = TRUE ;
- }
- INC ;
- }
- }
-
-
- void
- getparam(s, argv, errmes)
- char *s, *argv[], *errmes ;
- {
- if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
- else
- {
- FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
- exit(1) ;
- }
- }
-
-
- void
- init_edge_table(edgefile) /* Load reve edge table values. */
- char *edgefile ;
- {
- char buf[MAXLINE], *ptr ;
- int i, line ;
- FILE *fp = NULL ;
-
- if ((fp = find_file(edgefile)) == NULL)
- {
- FPRINTF(stderr, "Cannot open Edge Stability Table file\n") ;
- exit(1) ;
- }
- line = 0 ;
- while (fgets(buf, MAXLINE, fp) != NULL)
- {
- line++ ;
- if (buf[0] == '\n' || buf[0] == '#') continue ;
- if ((ptr = index(buf, '[')) == NULL)
- {
- FPRINTF(stderr, "Cannot read edge table file at line %d\n", line) ;
- exit(1) ;
- }
- SSCANF(ptr+1, "%d", &i) ;
- if ((ptr = index(buf, '=')) == NULL)
- {
- FPRINTF(stderr, "Cannot read edge table file at line %d\n", line) ;
- exit(1) ;
- }
- SSCANF(ptr+1, "%ld", &edges[i]) ;
- }
- FCLOSE(fp) ;
- for (i = 0 ; i < 3281; i++) edges[6560 - i] = - edges[i] ;
- }
-
-
- void
- show_best(move, note)
- int move ;
- long note ;
- {
- out.type = M_BEST ;
- out.move = move ;
- out.note = note ;
- out.depth = profmax ;
- WRITE(1, (char *) &out, sizeof(struct reve_out)) ;
- }
-